package com.lettcode;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description 两数相加
 * @Author Jlis
 * @Date 2021/7/18
 * @Version 1.0
 */
public class Lc0001 {
    public static void main(String[] args) {
        System.out.println(twoSum(new int[]{3,3},6));
    }

    public static int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> map = new HashMap<>();
        for(int i = 0; i < nums.length; i++){
            if(map.get(target - nums[i]) != null){
                return new int[]{map.get(target - nums[i]),i};
            }
            map.put(nums[i],i);
        }
        return new int[2];
    }
}
